<template>
	<view :style="themeColor">
		<view class="page">
			<view class="flex benben-position-layout flex flex-wrap align-center addCoupon_flex_0"
				:style="{height:(88+StatusBarRpx)+'rpx',paddingTop:StatusBarRpx+'rpx', }">
				<view class='flex flex-wrap align-center justify-between flex-sub addCoupon_fd0_0'>
					<view class='flex flex-wrap align-center addCoupon_fd0_0_c0' @tap.stop="handleJumpDiy"
						data-type="back" data-url="1">
						<text class='fu-iconfont2  addCoupon_fd0_0_c0_c0'>&#xE794;</text>
					</view>
					<text class='addCoupon_fd0_0_c1' v-if=" id==''">添加优惠券</text><text class='addCoupon_fd0_0_c1'
						v-if=" id!=''">编辑优惠券</text>
					<view class='flex flex-wrap align-center addCoupon_fd0_0_c0'>
					</view>
				</view>

			</view>
			<view :style="{height: (88+StatusBarRpx)+'rpx'}"></view>
			<!---flex布局flex布局开始-->
			<view class="flex benben-flex-layout flex-wrap align-center addCoupon_flex_1">
				<text class='addCoupon_fd1_0'>优惠券名称</text>
				<benben-input class='flex-sub addCoupon_fd1_1' type="text" :placeholder="`请输入优惠券名称`" confirm-type="done"
					:maxlength="-1" placeholder-style="color:#999;font-size:28rpx" v-model="couponData.name" />
			</view>

			<!---flex布局flex布局结束-->
			<!---flex布局flex布局开始-->
			<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout addCoupon_flex_2">
				<text class='addCoupon_fd2_0'>满减选择</text>
				<benben-select-diy ref="showSelectPopup1682752300558" class-name='flex flex-wrap align-center flex'
					:items.sync="fullReductionType" v-model="couponData.min_money_id" default-type="aid"
					default-label="name" :allow-cancel='true' type="radio" :disabled='false'>
					<template v-for='(item,key0) in fullReductionType'>
						<view v-if="item.isSelected" class='flex align-center justify-center flex addCoupon_fd2_1_c0'
							:key="key0" @tap="$refs.showSelectPopup1682752300558.tapHandle(key0)">
							<text class='addCoupon_fd2_1_c0_c0'>{{item.name}}</text>
						</view>
						<view v-else class='flex align-center justify-center flex addCoupon_fd2_1_c1' :key="key0"
							@tap="$refs.showSelectPopup1682752300558.tapHandle(key0)">
							<text class='addCoupon_fd2_1_c1_c0'>{{item.name}}</text>
						</view>
					</template>
				</benben-select-diy>
			</view>

			<!---flex布局flex布局结束-->
			<!---flex布局flex布局开始-->
			<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout addCoupon_flex_3">
				<text class='addCoupon_fd3_0'>满减金额选择</text>
				<benben-select-diy ref="showSelectPopup1682752847324" class-name='flex flex-wrap align-center flex'
					:items.sync="moneyType" v-model="couponData.reductionmoney_id" default-type="aid"
					default-label="money" :allow-cancel='true' type="radio" :disabled='false'>
					<template v-for='(item,key0) in moneyType'>
						<view v-if="item.isSelected" class='flex align-center justify-center flex addCoupon_fd3_1_c0'
							:key="key0" @tap="$refs.showSelectPopup1682752847324.tapHandle(key0)">
							<text class='addCoupon_fd3_1_c0_c0'>{{item.money}}</text>
						</view>
						<view v-else class='flex align-center justify-center flex addCoupon_fd3_1_c1' :key="key0"
							@tap="$refs.showSelectPopup1682752847324.tapHandle(key0)">
							<text class='addCoupon_fd3_1_c1_c0'>{{item.money}}</text>
						</view>
					</template>
				</benben-select-diy>
			</view>

			<!---flex布局flex布局结束-->
			<!---flex布局flex布局开始-->
			<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout addCoupon_flex_4">
				<view class='flex flex-wrap align-center addCoupon_fd4_0'>
					<text class='addCoupon_fd4_0_c0'>总发数量</text>
					<benben-input class='flex-sub addCoupon_fd4_0_c1' type="text" :placeholder="`可被领取的总数`"
						confirm-type="done" :maxlength="-1" placeholder-style="color:#999;font-size:28rpx"
						v-model="couponData.stock" />
				</view>
				<view class='flex flex-wrap align-center addCoupon_fd4_1' @tap.stop="pickerDiy1682753369044=true">
					<text class='addCoupon_fd4_0_c0'>截止使用时间</text>
					<benben-input class='flex-sub addCoupon_fd4_0_c1' type="text" :placeholder="`请选择`"
						confirm-type="done" :maxlength="-1" :disabled='true'
						placeholder-style="color:#999;font-size:28rpx" v-model="couponData.end_time" />
					<text class='fu-iconfont2  addCoupon_fd4_1_c2'>&#xe7f2;</text>
				</view>
			</view>

			<!---flex布局flex布局结束-->
			<benben-popup v-model="popupShow1684233224135" :mask="true" :mask-close-able="true" mode='center'>
				<!---确认添加弹窗flex布局开始-->
				<view class="flex flex-direction flex-wrap align-stretch benben-flex-layout addCoupon_flex_5">
					<text class='addCoupon_fd5_0'>提示</text>
					<text class='addCoupon_fd5_1'>优惠券创建后无法修改，只可停用确定要提交吗？</text>
					<view class='flex flex-wrap align-center'>
						<button class='addCoupon_fd5_2_c0' @tap.stop="popupShow1684233224135=false">取消</button>
						<button class='addCoupon_fd5_2_c1' @tap.stop="postCouponFunc()">确定</button>
					</view>
				</view>

				<!---确认添加弹窗flex布局结束-->

			</benben-popup>
			<!--日期选择器开始 -->
			<benben-picker ref="benbenWritePickerCodepicker6" :visible.sync="pickerDiy1682753369044"
				:value.sync='couponData.end_time' mode='date' :picker-height='88' :current='true' :mask-show='true'
				fields='day' :timeout='true' start-year='现在' end-year='2050-12-31'>
				<template #picker-header>
					<view class='flex flex-wrap align-center justify-between addCoupon_picker6_0'>
						<text class='addCoupon_picker6_0_c0'
							@tap="$refs.benbenWritePickerCodepicker6.cancel()">取消</text>
						<text class='addCoupon_picker6_0_c1'>请选择截止时间</text>
						<text class='addCoupon_picker6_0_c2'
							@tap="$refs.benbenWritePickerCodepicker6.pickerConfirm()">确认</text>
					</view>
				</template>
			</benben-picker>
			<!--日期选择器结束 -->
			<view class="flex flex-wrap align-start justify-center benben-position-layout flex addCoupon_flex_7">
				<button class='addCoupon_fd7_0' @tap.stop="popupShow1684233224135=true">完成</button>

			</view>
			<view :style="{height: '120rpx'}"></view>


		</view>
	</view>
</template>
<script>
	import {
		validate
	} from '@/common/utils/validate.js'

	export default {
		components: {},


		data() {
			return {
				"pickerDiy1682753369044": false,
				"popupShow1684233224135": false,
				"fullReductionType": [],
				"moneyType": [],
				"couponDetails": {},
				"couponData": {
					"aid": "",
					"name": "",
					"money": "",
					"end_time": "",
					"min_order_money": "",
					"last_stock": "",
					"stock": "",
					"reductionmoney_id": "",
					"min_money_id": ""
				},
				"id": ""
			};
		},
		computed: {
			themeColor() {
				return this.$store.getters.themeColor
			},

		},
		watch: {},
		onLoad(options) {
			let {
				id
			} = options
			if (id !== undefined) this.id = id
			this.getCouponDataFunc()
		},
		onUnload() {

		},
		onReady() {

		},
		onShow() {

		},
		onHide() {

		},
		onResize() {

		},
		onPullDownRefresh() {

		},
		onReachBottom(e) {

		},
		onPageScroll(e) {

		},
		methods: {
			//获取满减信息
			async getFullReductionFunc() {
				//请求方法
				//数据验证

				let datafullReductionType = await this.$api.get(global.apiUrls.post646cc9c12b520, {

				});

				if (datafullReductionType.data.code != 1) {
					this.$message.info(datafullReductionType.data.msg);
					return
				}
				let infofullReductionType = datafullReductionType.data;
				this.fullReductionType = infofullReductionType.data

			},
			//获取满减金额信息
			async getFullReductionMoneyFunc() {
				//请求方法
				//数据验证

				let datamoneyType = await this.$api.get(global.apiUrls.post646cc9cf79f3e, {

				});

				if (datamoneyType.data.code != 1) {
					this.$message.info(datamoneyType.data.msg);
					return
				}
				let infomoneyType = datamoneyType.data;
				this.moneyType = infomoneyType.data

			},
			//提交优惠券
			async postCouponFunc() {
				if (!validate(this.couponData.name, 'require')) {
					this.$message.info('请输入优惠券名称');
					return false;
				}
				if (!validate(this.couponData.min_money_id, 'require')) {
					this.$message.info('请选择满减选择');
					return false;
				}
				if (!validate(this.couponData.reductionmoney_id, 'require')) {
					this.$message.info('请选择满减金额');
					return false;
				}
				if (!validate(this.couponData.stock, 'require')) {
					this.$message.info('请输入总发数量');
					return false;
				}
				if (!validate(this.couponData.end_time, 'require')) {
					this.$message.info('请选择截止使用时间');
					return false;
				}
				//请求方法
				//数据验证

				let data64633006ec5e6 = await this.$api.dbPost(global.apiUrls.post64633006ec5e6, {
					aid: this.id,
					name: this.couponData.name,
					end_time: this.couponData.end_time,
					stock: this.couponData.stock,
					min_order_money: this.couponData.min_money_id,
					money: this.couponData.reductionmoney_id
				});
				if (!data64633006ec5e6) return
				if (data64633006ec5e6.data.code != 1) {
					this.$message.info(data64633006ec5e6.data.msg);
					return
				}



				this.$message.info('添加成功');
				this.popupShow1684233224135 = false;
				setTimeout(() => {
					this.$urouter.navigateBack(1);
				}, 500)
			},
			//获取优惠券信息
			async getDataFunc() {
				if (this.id != '') {
					//请求方法
					//数据验证

					let datacouponData = await this.$api.get(global.apiUrls.post646f4a0f3c158, {
						aid: this.id
					});

					if (datacouponData.data.code != 1) {
						this.$message.info(datacouponData.data.msg);
						return
					}
					let infocouponData = datacouponData.data;
					this.couponData = infocouponData.data

				}
			},
			//获取优惠券请求信息
			async getCouponDataFunc() {
				await this.getFullReductionFunc()
				await this.getFullReductionMoneyFunc()
				this.getDataFunc()
			}
		}
	};
</script>
<style lang="scss" scoped>
	.page {
		width: 100vw;
		overflow-x: hidden;
		min-height: calc(100vh - var(--window-bottom));
		background: rgba(248, 248, 248, 1);
		background-size: 100% auto;
	}

	.addCoupon_flex_0 {
		background: #fff;
		width: 750rpx;
		height: 88rpx;
		overflow: hidden;
		z-index: 10;
		top: 0rpx;
		background-size: 100% auto !important;
	}

	.addCoupon_fd0_0_c1 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333333;
		line-height: 50rpx;
	}

	.addCoupon_fd0_0_c0_c0 {
		font-size: 36rpx;
		font-weight: 500;
		color: #333;
		line-height: 88rpx;
	}

	.addCoupon_fd0_0_c0 {
		width: 200rpx;
		height: 88rpx;
	}

	.addCoupon_fd0_0 {
		padding: 0rpx 32rpx 0rpx 32rpx;
	}

	.addCoupon_flex_1 {
		background: rgba(255, 255, 255, 1);
		margin: 24rpx 24rpx 24rpx 24rpx;
		background-size: 100% auto !important;
		border-radius: 16rpx;
		padding: 32rpx 24rpx 32rpx 24rpx;
	}

	.addCoupon_fd1_1 {
		text-align: right;
		font-size: 28rpx;
		font-weight: 400;
		color: #333;
		margin: 0rpx 0rpx 0rpx 24rpx;
	}

	.addCoupon_fd1_0 {
		font-size: 28rpx;
		font-weight: 400;
		color: #333;
		line-height: 33rpx;
	}

	.addCoupon_flex_2 {
		background: #fff;
		margin: 24rpx 24rpx 0rpx 24rpx;
		background-size: 100% auto !important;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 32rpx 12rpx 8rpx 12rpx;
	}

	.addCoupon_fd2_1_c1_c0 {
		font-size: 24rpx;
		font-weight: 400;
		color: #333;
		line-height: 33rpx;
	}

	.addCoupon_fd2_1_c1 {
		background: rgba(248, 248, 248, 1);
		margin: 0rpx 16rpx 24rpx 16rpx;
		height: 64rpx;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		width: 193rpx;
		padding: 0rpx 10rpx 0rpx 10rpx;
	}

	.addCoupon_fd2_1_c0_c0 {
		font-size: 24rpx;
		font-weight: 400;
		color: #fff;
		line-height: 33rpx;
	}

	.addCoupon_fd2_1_c0 {
		background: #E31D1A;
		margin: 0rpx 16rpx 24rpx 16rpx;
		height: 64rpx;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		width: 193rpx;
		padding: 0rpx 10rpx 0rpx 10rpx;
	}

	.addCoupon_fd2_0 {
		margin: 0rpx 24rpx 32rpx 24rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333;
		line-height: 33rpx;
	}

	.addCoupon_flex_3 {
		background: #fff;
		margin: 24rpx 24rpx 0rpx 24rpx;
		background-size: 100% auto !important;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		padding: 32rpx 12rpx 8rpx 12rpx;
	}

	.addCoupon_fd3_1_c1_c0 {
		font-size: 24rpx;
		font-weight: 400;
		color: #333;
		line-height: 33rpx;
	}

	.addCoupon_fd3_1_c1 {
		background: rgba(248, 248, 248, 1);
		margin: 0rpx 16rpx 24rpx 16rpx;
		height: 64rpx;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		width: 193rpx;
		padding: 0rpx 10rpx 0rpx 10rpx;
	}

	.addCoupon_fd3_1_c0_c0 {
		font-size: 24rpx;
		font-weight: 400;
		color: #fff;
		line-height: 33rpx;
	}

	.addCoupon_fd3_1_c0 {
		background: #E31D1A;
		margin: 0rpx 16rpx 24rpx 16rpx;
		height: 64rpx;
		border-radius: 8rpx 8rpx 8rpx 8rpx;
		width: 193rpx;
		padding: 0rpx 10rpx 0rpx 10rpx;
	}

	.addCoupon_fd3_0 {
		margin: 0rpx 24rpx 32rpx 24rpx;
		font-size: 28rpx;
		font-weight: 400;
		color: #333;
		line-height: 33rpx;
	}

	.addCoupon_flex_4 {
		background: #fff;
		background-size: 100% auto !important;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
		margin: 24rpx 24rpx 0rpx 24rpx;
		padding: 0rpx 24rpx 0rpx 24rpx;
	}

	.addCoupon_fd4_1_c2 {
		font-size: 20rpx;
		color: #333;
		margin: 0rpx 0rpx 0rpx 16rpx;
	}

	.addCoupon_fd4_1 {
		padding: 32rpx 0rpx 32rpx 0rpx;
	}

	.addCoupon_fd4_0_c1 {
		text-align: right;
		font-size: 28rpx;
		font-weight: 400;
		color: #333;
		margin: 0rpx 0rpx 0rpx 24rpx;
	}

	.addCoupon_fd4_0_c0 {
		font-size: 28rpx;
		font-weight: 400;
		color: #333;
		line-height: 33rpx;
	}

	.addCoupon_fd4_0 {
		border-bottom: 1px solid #eee;
		padding: 32rpx 0rpx 32rpx 0rpx;
	}

	.addCoupon_flex_5 {
		background: #fff;
		width: 540rpx;
		background-size: 100% auto !important;
		border-radius: 16rpx 16rpx 16rpx 16rpx;
	}

	.addCoupon_fd5_2_c1 {
		border-top: 1px solid #eee;
		border-left: 1px solid #eee;
		background: #fff;
		border-radius: 0rpx 0rpx 16rpx 0rpx;
		font-size: 32rpx;
		color: rgba(227, 29, 26, 1);
		width: 269rpx;
		height: 94rpx;
		line-height: 94rpx;
		font-weight: 500;
	}

	.addCoupon_fd5_2_c0 {
		border-top: 1px solid #eee;
		border-right: 1px solid #eee;
		background: #fff;
		border-radius: 0rpx 0rpx 0rpx 16rpx;
		font-size: 32rpx;
		color: rgba(153, 153, 153, 1);
		width: 269rpx;
		height: 94rpx;
		line-height: 94rpx;
		font-weight: 500;
	}

	.addCoupon_fd5_1 {
		line-height: 45rpx;
		font-size: 32rpx;
		font-weight: 500;
		color: #333333;
		padding: 0rpx 56rpx 0rpx 56rpx;
		text-align: center;
		margin: 0rpx 0rpx 37rpx 0rpx;
	}

	.addCoupon_fd5_0 {
		line-height: 50rpx;
		font-size: 36rpx;
		font-weight: 800;
		color: #333333;
		margin: 40rpx 0rpx 32rpx 0rpx;
		padding: 0rpx 56rpx 0rpx 56rpx;
		text-align: center;
	}

	.addCoupon_picker6_0_c2 {
		font-size: 32rpx;
		font-weight: 400;
		color: rgba(255, 75, 51, 1);
		line-height: 40rpx;
	}

	.addCoupon_picker6_0_c1 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		line-height: 45rpx;
	}

	.addCoupon_picker6_0_c0 {
		font-size: 32rpx;
		font-weight: 400;
		color: #333;
		line-height: 40rpx;
	}

	.addCoupon_picker6_0 {
		border-bottom: 1px solid #eee;
		background: #fff;
		padding: 0rpx 32rpx 0rpx 32rpx;
		border-radius: 24rpx 24rpx 0rpx 0rpx;
		background-size: 100% auto !important;
		height: 100rpx;
	}

	.addCoupon_flex_7 {
		width: 750rpx;
		height: 120rpx;
		overflow: hidden;
		z-index: 10;
		bottom: calc(0rpx + var(--window-bottom));
	}

	.addCoupon_fd7_0 {
		background: #E31D1A;
		border-radius: 44rpx 44rpx 44rpx 44rpx;
		font-size: 32rpx;
		color: #fff;
		width: 686rpx;
		height: 88rpx;
		line-height: 88rpx;
	}
</style>